사이트 내 전체검색
특정 파일을 하위 디렉토리를 포함하여 찾아서 총 라인 수 세기
로빈아빠
https://cmd.kr/server/651 URL이 복사되었습니다.

본문

리눅스 명령

$ find . "*.java" -print | xargs cat | wc -l <- 확장자가 java인 모든 파일을 찾아서총 라인수를 센다.


아래는 shell script

#!/bin/bash

wc_total=0

function cnt {
for file in `ls $1`; do
if [ -d $file ]; then
cnt $file
else
if [ "`file -b $file | grep -i '\(ascii\|text\)'`" != "" ]; then
let "wc_total += `cat $file | wc -l`"
fi
fi
done

}

cnt .
echo $wc_total
exit 0

댓글목록

등록된 댓글이 없습니다.

1,139 (4/23P)

Search

Copyright © Cmd 명령어 18.191.33.136